package cas.ihep.hmss.queue;

import cas.ihep.hmss.Job;

import java.util.LinkedList;

/**
 * Created by chocolate on 2017/12/1.
 */
public class FifoQueue implements JobQueue {
    private final LinkedList<Job> fifoQue = new LinkedList<Job>();

    @Override
    public void enqueue(Job job) throws Exception {
        synchronized (fifoQue) {
            job.enqueueTime = System.currentTimeMillis();
            fifoQue.offerLast(job);
        }
    }

    @Override
    public Job dequeue(int s) throws Exception {
        synchronized (fifoQue) {
            if (!fifoQue.isEmpty()) {
                return fifoQue.pollFirst();
            }
            return null;
        }
    }
}
